<?php
require_once MODEL_DIR.'/TodoListModel.php';
$oTodoInstance = new TodoListModel();

if(isset($_GET['option'])){
	if(isset($_POST['submit'], $_POST['idTask'])){
		switch($_GET['option']){
			case 'check':
				if($_POST['statusTask'] == 2){
					$oTodoInstance->updateDate($_POST['idTask'], 'dateEndTask');
				}elseif($_POST['statusTask'] == 3){
					$aiassTasksList = $oTodoInstance->getTasks('WHERE idTask = '.$_POST['idTask']);
					$asmTask = $aiassTasksList[0];
					if($asmTask['statusTask'] != 3){
						$oTodoInstance->updateDate($_POST['idTask'], 'dateBeginTask');
					}
				}
				TodoListModel::editTask($_POST);
				header('Location: index.php?page=adminIndex&mod=todo&action=edit');
			break;
			case 'edit':
				$aiassTasksList = $oTodoInstance->getTasks('WHERE idTask = '.$_POST['idTask']);
				$asmTask = $aiassTasksList[0];
				require_once VIEW_DIR.'/formTodoListEdit.php';
			break;
			default:
				header('Location: index.php?page=adminIndex&mod=todo&action=edit');
			break;
		}
	}
}else{
	$aiassTasksList = $oTodoInstance->getTasks();
	require_once VIEW_DIR.'/formTodoListSelectEdit.php';
}
